<?php
	if (isset($_POST['text2convert']) && ($_POST['text2convert'] != "")) 
	{
	    die("get in");
		$content = htmlentities($_POST['text2convert']);

		$lines = preg_split("/\\r\\n|\\r|\\n/", $content);
		
		$cnt = count($lines);
		
		$result = "\r";
		$last_indent = 0;
		for ($i = 0; $i < $cnt; $i++)
		{
			$firstChar = $lines[$i][0];
			
			if (($firstChar != "!")&&($firstChar != " ")&&($lines[$i] != "end"))
			{
				$fuck = $lines[$i];
				$result .= "sendln '$fuck'\r\n";
				$result .= "wait '#'\r\n";
				$last_indent = 0;
			}
			else if ($firstChar == " ")
			{
				$secondChar = $lines[$i][1];
				if (($secondChar != "!")&&(strpos($lines[$i],'vlan add default') == false)
					 && (strpos($lines[$i],'vlan pvid') == false))
				{
					$result .= "sendln '$lines[$i]'\r\n";
					$result .= "wait '#'\r\n";
				}
				$last_indent = 1;
			}
			else if($firstChar == "!")
			{
				if ($last_indent == 1)
				{
					$result .= "sendln 'exit'\r\n";
					$result .= "wait '#'\r\n";
				}
				$last_indent = 0;
			}
		}
		echo "QUYENLV";
		die($result);
	}	
?>